#include "yocto/utest/run.hpp"
#include "kernel/solution.hpp"

#include "yocto/ios/ocstream.hpp"
#include "yocto/lua/lua-state.hpp"
#include "yocto/lua/lua-config.hpp"
#include "yocto/code/rand.hpp"

using namespace yocto;


YOCTO_UNIT_TEST_IMPL(solution)
{
	_rand.wseed();
	
	if( argc <= 1 )
		throw exception("%s: need script.lua", argv[0] );
	Library     lib;
	ChemSys     chs(lib);
	Initializer init_in(lib);
	Initializer init_out(lib);
	
	Lua::State VM;
	lua_State *L = VM();
	Lua::Config::DoFile( L, argv[1] );
	lib.load(L,"library");
	lib.close();
	
	chs.load(L,"chemsys");
	chs.compile();
	
	
	init_in.load(L,"init_in");
	init_in.compile();
	
	init_out.load(L,"init_out");
	init_out.compile();
	
	init_in.setup(chs, 0);
	Solution s_in( lib );
	s_in.load_from(chs);
	std::cerr << "In=" << std::endl;
	s_in.display(std::cerr);
	
	init_out.setup(chs,0);
	Solution s_out(lib);
	s_out.load_from(chs);
	std::cerr << "Out=" << std::endl;
	s_out.display(std::cerr);
	
	Solution dS(lib);
	dS.zero();
	dS.addLeak( 0, 1, s_in, s_out );
	std::cerr << "dS_full=" << std::endl;
	dS.display(std::cerr);
	
	chs.updateRate( dS, 0.0, s_in );
	std::cerr << "dS_damp=" << std::endl;
	dS.display(std::cerr);
	
}
YOCTO_UNIT_TEST_DONE()
